home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / tip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  2.4 KB  |  114 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    Feb '91    Bill Simpson
  5.  *        rlsd control and improved dialer
  6.  */
  7. #include "global.h"
  8. #include "config.h"
  9. #ifdef ASY
  10. #include "mbuf.h"
  11. #include "proc.h"
  12. #include "iface.h"
  13. #ifndef    UNIX
  14. #include "8250.h"
  15. #endif
  16. #include "asy.h"
  17. #include "tty.h"
  18. #include "session.h"
  19. #include "socket.h"
  20. #include "commands.h"
  21.  
  22. static void tip_out __ARGS((int dev,void *n1,void *n2));
  23.  
  24. /* Execute user telnet command */
  25. int
  26. dotip(argc,argv,p)
  27. int argc;
  28. char *argv[];
  29. void *p;
  30. {
  31.     struct session *sp;
  32.     struct iface *ifp;
  33.     char *ifn;
  34.     int c, (*rawsave) __ARGS((struct iface *,struct mbuf *));
  35.  
  36.     if((ifp = if_lookup(argv[1])) == NULLIF){
  37.         tprintf(Badif,argv[1]);
  38.         return 1;
  39.     }
  40.     if( ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp ){
  41.         tprintf(Badax,argv[1]);
  42.         return 1;
  43.     }
  44.     if(ifp->raw == bitbucket){
  45.         tprintf("tip or dialer session already active on %s\n",argv[1]);
  46.         return 1;
  47.     }
  48.  
  49.     /* Allocate a session descriptor */
  50.     if((sp = newsession(argv[1],TIP,0,1)) == NULLSESSION){
  51.         tputs(Nosess);
  52.         keywait(NULLCHAR,1);
  53.         return 1;
  54.     }
  55.  
  56.     /* Save output handler and temporarily redirect output to null */
  57.     rawsave = ifp->raw;
  58.     ifp->raw = bitbucket;
  59.  
  60.     /* Suspend the packet input driver. Note that the transmit driver
  61.      * is left running since we use it to send buffers to the line.
  62.      */
  63.     suspend(ifp->proc);
  64.  
  65.     /* Put tty into raw mode */
  66.     sp->ttystate.echo = 0;
  67.     sp->ttystate.edit = 0;
  68.     sockmode(sp->output,SOCK_BINARY);
  69.  
  70.     /* Now fork into two paths, one rx, one tx */
  71.     ifn = if_name(ifp," tip out");
  72.     sp->proc1 = newproc(ifn,256,tip_out,ifp->dev,NULL,NULL,0);
  73.     xfree(ifn);
  74.  
  75.     ifn = if_name( ifp, " tip in" );
  76.     chname( Curproc, ifn );
  77.     xfree( ifn );
  78.  
  79.     /* bring the line up (just in case) */
  80. /*
  81.     if ( ifp->ioctl != NULL )
  82.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  83. */
  84.     while((c = get_asy(ifp->dev)) != -1)
  85.         tputc(c & 0x7f);
  86.     tflush();
  87.  
  88.     killproc(sp->proc1);
  89.     sp->proc1 = NULLPROC;
  90.     ifp->raw = rawsave;
  91.     resume(ifp->proc);
  92.     keywait(NULLCHAR,1);
  93.     freesession(sp);
  94.     return 0;
  95. }
  96.  
  97.  
  98. /* Output process, DTE version */
  99. static void
  100. tip_out(dev,n1,n2)
  101. int dev;
  102. void *n1,*n2;
  103. {
  104.     int c;
  105.  
  106.     while((c = recvchar(Curproc->input)) != EOF){
  107.         struct mbuf *bp = pushdown(NULLBUF,1);
  108.         bp->data[0] = (c == '\n') ? '\r' : c;
  109.         asy_send(dev,bp);
  110.         Asy[dev].iface->lastsent = secclock();
  111.     }
  112. }
  113.  
  114. #endif /* ASY */